import request from "@/utils/request"

interface Role {
    roleId: number,
    roleName: String,
    roleDesc: String
}

export const getAllRole = () => {
    return request.get('/role');
}

/**
 * 分页查询权限
 * @param pageCurrent 
 * @param pageSize 
 * @returns 
 */
export const getRoleListByPage = (pageCurrent: Number, pageSize: Number) => {
    return request.get(`/role/page?pageCurrent=${pageCurrent}&pageSize=${pageSize}`);
}

/**
 * 
 * @param roleId 根据权限Id删除权限
 * @returns 
 */
export const deleteRoleById = (roleId: Number) => {
    return request.delete(`/role/${roleId}`);
}

/**
 * 添加权限
 * @param data 
 * @returns 
 */
export const putOneRole = (data: any) => {
    return request.put(`/role`, {
        roleName: data.roleName,
        roleDesc: data.roleDesc
    })
}

/**
 * 根据id编号来编辑权限
 * @param data 
 * @returns 
 */
export const postOneRoleById = (data: Role) => {
    return request.post(`/role`, {
        roleId: data.roleId,
        roleName: data.roleName,
        roleDesc: data.roleDesc
    })
}

/**
 * 获取所有权限
 * @returns 
 */
export const getAllMenu = () => {
    return request.get(`/menu/all`);
}

/**
 * 根据角色id获取已经选择的权限id
 * @param roleId 
 * @returns 
 */
export const getRoleMenuByRoleId = (roleId: Number) => {
    return request.get(`/role/${roleId}`)
}

/**
 * 添加权限
 * @param roleId 角色id
 * @param menuId 菜单id
 * @returns 
 */
export const addRoleMenuByRoleIdAndMenuId = (roleId: number, menuId: Number) => {
    return request.post(`/role/add/menu`, {
        rid: roleId,
        mid: menuId
    })
}

/**
 * 删除权限
 * @param roleId 
 * @param menuId 
 * @returns 
 */
export const removeRoleMenuByRoleIdAndMenuId = (roleId: Number, menuId: Number) => {
    return request.post(`/role/remove/menu`, {
        rid: roleId,
        mid: menuId
    })
}